package com.joshluisaac.zFileio;

import java.io.File;

public class DiskSpaceDetail {
	public static void main(String[] args) {

		File file = new File("/home/joshua");

		/*
		 * The difference between getFreeSpace() and getUsableSpace() is getFreeSpace() will
		 * give the actual space that is free in the partition. getUsableSpace()
		 * will give the free space available to the JVM at that time(may be due
		 * to user level restrictions or some other restrictions at OS level,
		 * JVM will not have the full access to all the Free space in the
		 * partition)
		 */

		long totalSpace = file.getTotalSpace(); // total disk space in bytes.
		long usableSpace = file.getUsableSpace(); // /unallocated / free disk
													// space in bytes.
		long freeSpace = file.getFreeSpace(); // unallocated / free disk space
												// in bytes.

		System.out.println(" === Partition Detail ===");

		System.out.println(" === bytes ===");
		System.out.println("Total size : " + totalSpace + " bytes");
		System.out.println("Space free : " + usableSpace + " bytes");
		System.out.println("Space free : " + freeSpace + " bytes");

		System.out.println(" === mega bytes ===");
		System.out.println("Total size : " + totalSpace / 1024 / 1024 / 1024
				+ " gb");
		System.out.println("Space free : " + usableSpace / 1024 / 1024 / 1024
				+ " gb");
		System.out.println("Space free : " + freeSpace / 1024 / 1024 / 1024
				+ " gb");
	}
}
